package com.fanbai.score.common.activity;

import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.fanbai.score.R;
import com.fanbai.score.common.Manager.ActivityManager;
import com.fanbai.score.common.Utils.ImageUtils;
import com.fanbai.score.common.base.BaseActivity;
import com.fanbai.score.common.view.divider.DividerItemDecoration;
import com.fanbai.score.user.bean.ActInfo_Bean;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by acer on 2017/5/14.
 * 共用的列表展示界面
 * status--
 * 用户
 *  jifen-积分记录
 *  shangpin-商品兑换记录
 * 股东
 *  shops -商户列表
 *  staffList-店员管理
 */

public class CommonList_Activity extends BaseActivity{

    @BindView(R.id.view_recyclerView)
    RecyclerView mRecyclerView;

    private String status = "";

    @Override
    protected int getLayoutID() {
        status = getIntent().getExtras().getString("status");
        return R.layout.user_activity_commonlist;
    }

    @Override
    public String getTitleName() {
        if(status.equals("jifen")){//红包兑换记录、积分记录
            return "积分记录";
        }else if(status.equals("hongbao")){
            return "红包兑换记录";
        }else if(status.equals("shangpin")){
            return "商品兑换记录";
        }else if(status.equals("xiaofei")){
            return "消费记录";
        }else if(status.equals("guirenbi")){
            return "贵人币兑换记录";
        }else if(status.equals("huodongquan")){//活动券记录
            return "活动券";
        }else if(status.equals("shops")){//股东中商户列表
            return "商户列表";
        }else if(status.equals("actList")){//股东中活动列表
            return "活动列表";
        }else if(status.equals("staffList")){//股东中店员管理
            return "店员列表";
        }else if(status.equals("shopCount")){//管理中店铺统计列表
            return "店铺统计";
        }else if(status.equals("actCount")){//管理中活动统计列表
            return "活动统计";
        }else if(status.equals("actList")){//活动
            return "活动";
        }
        return "";
    }

    @Override
    protected void initView() {
    }

    private void setmRecyclerView(int layout, final List<Parcelable> data){
        mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
        mRecyclerView.addItemDecoration(new DividerItemDecoration(ctx, DividerItemDecoration.VERTICAL_LIST));
        CommonAdapter adapter = new CommonAdapter<Parcelable>(ctx, layout, data) {
            @Override
            protected void convert(ViewHolder holder, Parcelable o, int position) {
                if(status.equals("jifen") || status.equals("hongbao")){
                    holder.setText(R.id.userItemActivity_leftTxt, ""+o);
                }else if(status.equals("shangpin")){
                    holder.setText(R.id.userItemActivity_goodsRecordContent, ""+o);
                }else if(status.equals("xiaofei")){
                    holder.setText(R.id.userItemActivity_consumpionRecord, ""+o);
                }else if(status.equals("guirenbi")){
                    holder.setText(R.id.itemTextView, ""+o);
                }else if(status.equals("huodongquan")){
                    holder.setText(R.id.userItemActivity_couponFaceValue, ""+o);
                }else if(status.equals("shops")){//股东中商户管理
                    holder.setText(R.id.manageItemShopsList_shopName, ""+o);
                }else if(status.equals("staffList")){//股东中店员管理
                    holder.setText(R.id.manageItemShopsList_shopName, ""+o);
                }else if(status.equals("shopCount")) {//管理中店铺统计
                    holder.setText(R.id.manageItemShopList_name, ""+o);
                }else if(status.equals("actCount")){//管理中活动统计
                    holder.setText(R.id.manageItemActCount_tip, ""+o);
                }else if(status.equals("actList")){//活动列表
                    ActInfo_Bean actInfoBean = (ActInfo_Bean) o;
                    ImageUtils.show(ctx, actInfoBean.getActlogoimage(), (ImageView) holder.getView(R.id.itemImgView), R.mipmap.icon_img_defeated);
                }
            }
        };
        adapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                if(status.equals("jifen") || status.equals("hongbao")){
                }else if(status.equals("shangpin")){
                }else if(status.equals("xiaofei")){
                }else if(status.equals("guirenbi")){
                }else if(status.equals("huodongquan")){
                }else if(status.equals("shops")){//股东中商户管理
                }else if(status.equals("staffList")){//股东中店员管理
                }else if(status.equals("shopCount")) {//管理中店铺统计
                }else if(status.equals("actCount")){//管理中活动统计
                }else if(status.equals("actList")){//活动列表
                    ActInfo_Bean actInfoBean = (ActInfo_Bean) data.get(position);
                    Bundle bundle = new Bundle();
                    bundle.putString("url", actInfoBean.getActurl());
                    jumpToActivity(WebView_Activity.class, bundle);
                }
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() {
        ArrayList<Parcelable> data = null;
        try {
            data = getIntent().getExtras().getParcelableArrayList("beans");
        }catch (NullPointerException e){
            data = null;
        }
        if(data != null && data.size() > 0){
            int layout = 0;
            if(status.equals("jifen") || status.equals("hongbao")){//红包兑换记录、积分记录
                layout = R.layout.user_item_activity_consumption;
            }else if(status.equals("shangpin")){
                layout = R.layout.user_item_activity_goodsrecord;
            }else if(status.equals("xiaofei")){
                layout = R.layout.user_item_activity_consumptionrecord;
            }else if(status.equals("guirenbi")){
                layout = R.layout.item_textview;
            }else if(status.equals("huodongquan")){//活动券记录
                layout = R.layout.user_item_activity_couponrecord;
            }else if(status.equals("shops") || status.equals("staffList")){//股东中商户列表
                layout = R.layout.business_item_shopslist;
            }else if(status.equals("shopCount")){//管理中店铺统计
                layout = R.layout.manage_item_shopcount;
            }else if(status.equals("actCount")){//管理中活动统计
                layout = R.layout.manage_item_actcount;
            }else if(status.equals("actList")){
                layout = R.layout.item_imgview;
            }
            setmRecyclerView(layout, data);
        }
    }

    @Override
    protected void initListener() {

    }

    @Override
    public int getTitleLeftName() {
        return R.mipmap.back_click;
    }

    @Override
    public void onClickTitleLeft() {
        ActivityManager.getInstance().finishActivity();
    }


}
